<%@ page import="entity.User" %>
<%@ page import="java.util.*" %><%--
  Created by IntelliJ IDEA.
  User: Teacher
  Date: 2025/3/26
  Time: 14:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>EL表达式</title>
</head>
<body>
<%
    //    pageContext.setAttribute("msg","Hello pageContext");
//    request.setAttribute("msg","Hello request");
//    session.setAttribute("msg","Hello session");
//    application.setAttribute("msg","Hello application");
    User user = new User(1, "admin", "123456", "13812345678", "江苏-南京");
    request.setAttribute("user", user);
    User user2 = new User(2, "jack", "111111", "13812345678", "江苏-南京");
    User user3 = new User(3, "tom", "222222", "13812345678", "江苏-南京");
    List<User> users = new ArrayList<User>(Arrays.asList(user, user2, user3));
    request.setAttribute("users", users);
    Map<String, User> map = new HashMap<String, User>();
    map.put("u1", user);
    map.put("u2", user2);
    map.put("u3", user3);
    request.setAttribute("map", map);
%>
<h2>访问作用域数据</h2>
pageContext:${pageScope.msg}<br>
request:${requestScope.msg}<br>
session:${sessionScope.msg}<br>
application:${applicationScope.msg}<br>
<h2>访问对象信息</h2>
user:${user}<br>
${user.id}-${user.username}-${user.password}<br>
<h2>获取应用名</h2>
应用名:<%=request.getContextPath()%><br>
<!-- 在EL表达式中,没有request内置对象,我们通过pageContext获取到request -->
应用名:
<%
    HttpServletRequest a = (HttpServletRequest) pageContext.getRequest();
    String path = a.getContextPath();
    out.print(path);
//    ((HttpServletRequest) pageContext.getRequest()).getContextPath()
%><br>
应用名:${pageContext.request.contextPath}
<h2>访问List集合</h2>
${users[0].id}--${users[0].username}--${users[0].password}<br>
${users[1].id}--${users[1].username}--${users[1].password}<br>
${users[2].id}--${users[2].username}--${users[2].password}<br>
<h2>访问Map集合</h2>
${map['u1'].id}--${map['u1'].username}<br>
${map.u2.id}--${map.u2.username}<br>
<h2>运算</h2>
${3+2}<br>
${3-2}<br>
${3*2}<br>
${3/2}<br>
${3%2}<br>
${1 > 2 ? "1大于2" : "1不大于2"}<br>
${1 > 2}<br>
${1 > 2 and 2 > 1}<br>
${1 > 2 or 2 > 1}<br>
${1 == 1}<br>
${1 == "1"}<br>
${1 eq "1"}<br>
${empty user}<br>
${empty emp}<br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</body>
</html>
